﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="KuluOsa", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(KuluOsa))]
    public class KuluOsaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKuluOsa clazz;
        
        public KuluOsaSerializer(IKuluOsa clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.OsaSumma!=null) {
                Writer.WriteStartElement("OsaSumma");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.OsaSumma))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ValuutaKL!=null) {
                Writer.WriteStartElement("ValuutaKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ValuutaKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKP!=null) {
                Writer.WriteStartElement("AlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Osaline!=null) {
                Writer.WriteStartElement("Osaline");
                global::Xtee.Core.SerializationMetadata metaOsaline = this.GetMetaData(clazz.Osaline);
                Writer.WriteTypeAttribute(metaOsaline.TypeQualifiedName.Namespace, metaOsaline.TypeQualifiedName.Name);
                metaOsaline.NewSerializer(clazz.Osaline).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.OnRiigiOsa!=null) {
                Writer.WriteStartElement("OnRiigiOsa");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.OnRiigiOsa))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.SulgemiseKP!=null) {
                Writer.WriteStartElement("SulgemiseKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.SulgemiseKP))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="OsaSumma") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OsaSumma = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("OsaSumma")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ValuutaKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.ValuutaKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ValuutaKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Osaline") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaOsaline = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsaline>(Reader, "Osaline", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                    clazz.Osaline = metaOsaline.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsaline>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Osaline");
                        metaOsaline.NewSerializer(clazz.Osaline).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="OnRiigiOsa") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OnRiigiOsa = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("OnRiigiOsa")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SulgemiseKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SulgemiseKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("SulgemiseKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
